#include "StreamVideoWidget.h"

QStringList GetCameraList();

StreamVideoWidget::StreamVideoWidget(void)
{
	// create interface
	createInterface();
	// load source list
	loadSourceList();

	// connect signals
	connect(m_chkPaused, SIGNAL(stateChanged(int)), this, SLOT(onSetPaused(int)));
	connect(m_chkPlayback, SIGNAL(stateChanged(int)), this, SLOT(onSetPlayback(int)));
	connect(m_cmbSources, SIGNAL(currentIndexChanged(int)), this, SLOT(onChangeSource(int)));
}

StreamVideoWidget::~StreamVideoWidget(void)
{
}

void StreamVideoWidget::loadSourceList()
{
	m_cmbSources->addItems(GetCameraList());
}

void StreamVideoWidget::createInterface()
{
	m_lblSource = new QLabel(tr(LABEL_SOURCE));
	m_cmbSources = new QComboBox();
	m_chkPaused = new QCheckBox(tr(LABEL_PAUSE));
	m_chkPaused->setChecked(false);
	m_chkPlayback = new QCheckBox(tr(LABEL_PLAYBACK));
	m_chkPlayback->setChecked(false);
	m_chkPlayback->setEnabled(false);
	m_cmbSources->setFixedWidth(155);

	QHBoxLayout *layout = new QHBoxLayout();
	setLayout(layout);
	layout->addWidget(m_lblSource);
	layout->addWidget(m_cmbSources, 1);
	layout->addWidget(m_chkPaused);
	layout->addWidget(m_chkPlayback);

	setTitle(tr(TITLE_SECTION_VIDEO));
}

void StreamVideoWidget::onSetPaused(int state)
{
	if (state == Qt::Checked)
		emit onPause(true);
	else
		emit onPause(false);
}

void StreamVideoWidget::onSetPlayback(int state)
{
	if (state == Qt::Checked)
		emit onPlayback(true);
	else
		emit onPlayback(false);
}

void StreamVideoWidget::onChangeSource(int idx)
{
	emit onSourceChanged(idx);
}

void StreamVideoWidget::enablePlayback(const bool bEnabled)
{
	m_chkPlayback->setEnabled(bEnabled);
	if (!bEnabled)
		m_chkPlayback->setChecked(false);
}
